<?php
/**
* album interface
*/
class AlbumInterface
{
	
	public static function search(
		$condition=array(),
		$page=1,
		$order='date_create asc',
		$limit=20
	) {
		
		# construct conditional string and param
		$query_string		= array();
		$param_array		= array();
		$condition_string 	= '';
		foreach ($condition as $key => $row) {
			
			switch ($key) {
				case 'datefrom':
					$query_string[] = 'a.`created` > :'.$key.'';
					$param_array[':'.$key] = $row;
				break;
				case 'dateto':
					$query_string[] = 'a.`created` < :'.$key.'';
					$param_array[':'.$key] = $row;
				break;
				case 'user_id': case 'artist_id':
					$query_string[] = $key.'=:'.$key;
					$param_array[':'.$key] = $row;
				break;
				case 'name':
					$query_string[] = 't.`'.$key.'` LIKE :'.$key;
					$param_array[':'.$key] = '%'.$row.'%';
				break;
				default:
					$query_string[] = '`'.$key.'` LIKE :'.$key;
					$param_array[':'.$key] = '%'.$row.'%';
				break;
			}
		}
		$condition_string = implode(' AND ',$query_string);
		
		
		return Album::model()->findAll(array(
			'select'	=>array('id','name','artist_id','year','tags'),
			'condition'	=>$condition_string,
			'params'	=>$param_array,
			'limit'		=>$limit,
			'offset'	=>(($page-1)*$limit),
			'order'		=>$order,
		));
	}
	
}

?>